<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="./assets/css/login.css" media="all">
    <link rel="stylesheet" href="./assets/css/star.css">

    <script>
        if (window != top)
            top.location.replace(location.href);
    </script>
</head>

<!--<body style="background-image: url('assets/images/background.png')">-->
<body >

<div class="star comet " ></div>

<div class="login-wrapper" style="z-index: 9999">

    <div class="login-header">
        <img src="assets/images/logo.png">
    </div>

    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verify="required" placeholder="账号"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verify="required" placeholder="密码"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="code" type="text" lay-verify="required" placeholder="验证码"
                                       class="layui-input">
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 10px;">
                                <img class="login-captcha" src="">
                            </div>
                        </div>
                    </div>
                </div>
                <input type="hidden" id = "uuid" value="">
                <!--<div class="layui-form-item">-->
                    <!--<a href="javascript:;" class="layui-link">帐号注册</a>-->
                    <!--<a href="javascript:;" class="layui-link pull-right">忘记密码？</a>-->
                <!--</div>-->
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
                </div>
                <div class="layui-form-item login-other">
                    <label>第三方登录</label>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                    <!--<a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>-->
                </div>
            </form>
        </div>
    </div>

    <div class="login-footer">
        <p>© 2018 <a href="https://easyweb.vip" target="_blank"> hepg-cloud 版权所有</a></p>
        <!--<p>-->
            <!--<span><a href="https://github.com/whvcse/EasyWeb" target="_blank">前往github</a></span>-->
            <!--<span><a href="https://gitee.com/whvse/EasyWeb" target="_blank">前往gitee</a></span>-->
            <!--<span><a href="http://easyweb.vip" target="_blank">文档说明</a></span>-->
        <!--</p>-->
    </div>
</div>
<script src="./assets/js/star.js"></script>
<script type="text/javascript" src="./assets/libs/layui/layui.js"></script>
<script>
    layui.config({
        base:"./module/"
    })

    layui.use(['layer', 'form','config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var config = layui.config;
        config.removeUser();
        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            layer.load(2);
            $.ajax({
                url:"auth/oauth/token?code="+obj.field.code+"&randomUuid="+$("#uuid").val(),
                type:"post",
                data:{
                    username:obj.field.username,
                    password:obj.field.password,
                    // code:obj.field.code,
                    grant_type:"password",
                    // randomUuid:$("#uuid").val(),
                    scope:"server"
                },
                headers:{
                    Authorization:"Basic Zm9udDoxMjM0NTY="
                },
                dataType:"json",
                success:function(data){
                    layer.closeAll('loading');
                    if(data &&  data.access_token){
                        config.putToken(data.access_token);
                        config.putUser({
                            account:data.account,
                            username:data.username,
                            wechat:data.wechat,
                            qq:data.qq
                        });
                        layer.msg('登录成功', {icon: 1, time: 100}, function () {
                            location.replace('./index.html');
                        });
                    }else if(data && data.msg){
                        layer.msg(data.msg, {icon: 2, time: 1500});
                        $('.login-captcha').click();
                    }
                    console.log(data);
                },
                error:function(data){
                    layer.closeAll('loading');
                    if(data.status == 428){
                        layer.msg("验证码错误",{icon: 2, time: 1500})
                        $('.login-captcha').click();
                    }else{
                        layer.msg("系统异常",{icon: 2, time: 1500})
                        $('.login-captcha').click();
                    }
                }
            })
            return false;
        });
        // 初始化图形验证码
        $('.login-captcha').attr("src","./code?uuid="+guid());
        // 图形验证码
        $('.login-captcha').click(function () {
            this.src =  "./code?uuid="+guid();
        });

        function guid() {
            function S4() {
                return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
            }
            var uuid =  (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
            $("#uuid").val(uuid);
            return uuid;
        }
    });
</script>
</body>
</html>